<?php

class AdminAction extends Action{

    function login() {
    	$this->display();
    }

	function checklogin(){
		$username = $this->_isempty($_POST['username'],'账号不能为空');
		$password = $this->_isempty($_POST['password'],'密码不能为空');

		if(md5($_POST['verify']) == $_SESSION['verify']){
			$m  = M('admin');
			$data['username'] = $username;
			$data['password'] = encrypt($password);
			$admin = $m->where($data)->find();

			if($admin != null){
				$_SESSION['username'] = $username;
				$_SESSION['password'] = $password;
				$_SESSION['adminid'] = $admin['id'];
				$_SESSION['code'] = C('SYSTEM_CODE');
				$logid = add1log($admin['id'],'登录 ID:'.$admin['id'].'-'.$username,1);
				$_SESSION['logid'] = $logid;

				$this->redirect('Index/index');
//				$this->assign('jumpUrl',__APP__.'/Index/index/');
//				$this->assign('waitSecond','3');
//				$this->success("登录成功");
			}else{
				$this->assign('jumpUrl',__APP__.'/Admin/login/');
				$this->assign('waitSecond','3');
				$this->error("登录失败，账号或密码错误，请重新输入");
			}
		}else{
			$this->assign('jumpUrl',__APP__.'/Admin/login/');
			$this->assign('waitSecond','3');
			$this->error("验证码错误，请重新输入");
		}


	}


	public function verify()
	{
		import('@.ORG.Image');
		Image::buildImageVerify(5,1,gif,78,30,'verify');
	}


	public function _isempty($key,$str){
		if(empty($key)){
			$this->error($str);
		}else{
			return $key;
		}
	}

	public function logout(){
		outlog($_SESSION['logid'],'登出后台',1);
		session_destroy();
		$this->assign('jumpUrl',__APP__.'/Admin/login/');
		$this->assign('waitSecond','3');
		$this->success("注销成功！");
	}




}
?>